package idv.arthur.work;

import java.io.IOException;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class GetSN
 */
//@WebServlet(description = "取得計畫案目前的序號", urlPatterns = { "/GetSN" })
public class GetSN extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetSN() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		Widgets wid = new Widgets(); 
		String resultQuery ="";
		String type = request.getParameter("snType");
		
		/** 數字的格式 **/
		NumberFormat numberFormat = new DecimalFormat("#00");
		
		try { 
			resultQuery = String.valueOf(wid.getSNandAdd(type, true));
			resultQuery = numberFormat.format(Double.valueOf(resultQuery));
		} catch (SQLException e) {
			resultQuery = e.toString();
		}
		
		response.setContentType("application/text");
		response.setCharacterEncoding("UTF-8");
		response.getWriter().write(resultQuery);
		
	}

}
